package com.net.lnk.batch.bank.batch;

import org.springframework.batch.item.ItemProcessor;

import com.net.lnk.batch.bank.dto.BankcardDTO;
import com.net.lnk.batch.bank.model.BankcardModel;

public class BankcardItemProcessor implements ItemProcessor<BankcardDTO, BankcardModel> {

	public BankcardModel process(BankcardDTO item) {
		if ("UPI Token".equals(item.getCardName())) {
			item.setCardName("");
		}

		String originalBankName = item.getBankName();
		String bankName = originalBankName.substring(0, originalBankName.lastIndexOf("("));
		String bankCode = originalBankName.substring(originalBankName.lastIndexOf("(") + 1,
				originalBankName.lastIndexOf(")"));
		BankcardModel model = new BankcardModel();
		model.setBankName(bankName);
		model.setBankCode(bankCode);
		model.setCardName(item.getCardName());
		model.setCardNoLength(item.getCardNoLength());
		model.setCardNoSample(item.getCardNoSample());
		model.setBinLength(item.getBinLength());
		model.setBin(item.getBin());
		model.setCardType(item.getCardType());
		return model;
	}

}
